package org.eden.web.controller;

import org.eden.web.pojo.LoginReq;
import org.eden.web.pojo.Response;
import org.eden.web.pojo.States;
import org.eden.web.service.LoginService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@RestController
public class LoginController {
    private static final Logger logger = LoggerFactory.getLogger(LoginController.class);

    @PostMapping("/login/username")
    public Response login(LoginReq loginReq) {
        logger.info("req = " + loginReq);
        LoginService passwordLoginService = LoginService.instances.get("PasswordLoginService");
        return passwordLoginService.login(loginReq.getUser(), loginReq.getReq());
    }

    @PostMapping("/login/sms")
    public Response loginByEmail(LoginReq loginReq) {
        LoginService passwordLoginService = LoginService.instances.get("SmsLoginService");
        return passwordLoginService.login(loginReq.getUser(), loginReq.getReq());
    }

    @RequestMapping("/access_denied")
    public Response accessDenied() {
        return new Response(States.ACCESS_DENIED);
    }

    @RequestMapping("/auth_denied")
    public Response authDenied() {
        return new Response(States.AUTH_DENIED);
    }
}
